package com.epalmpay.handler;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
//import com.github.binarywang.demo.spring.builder.AbstractBuilder;
//import com.github.binarywang.demo.spring.builder.ImageBuilder;
//import com.github.binarywang.demo.spring.builder.TextBuilder;
//import com.github.binarywang.demo.spring.dto.WxMenuKey;
//import com.github.binarywang.demo.spring.service.BaseWxService;
import com.epalmpay.builder.AbstractBuilder;
import com.epalmpay.builder.ImageBuilder;
import com.epalmpay.builder.TextBuilder;
import com.epalmpay.dto.system.WxMenuKey;
import com.epalmpay.service.weixin.IWxBaseService;
import com.epalmpay.service.weixin.impl.BaseWxService;
import com.epalmpay.service.weixin.impl.WxService;

import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;

/**
 * 
 * @author Binary Wang
 *
 */
@Component
public  class MenuHandler extends AbstractHandler {

    @Autowired
	protected WxService wxService;
	@Autowired
    protected IWxBaseService wxBaseService;
	
  @Override
  public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
      Map<String, Object> context, WxMpService wxMpService,
      WxSessionManager sessionManager) {
	  System.out.println("----------点击事件-----------"); 

	  
	  
//	  String href = "<a href=\"" + wxMpService.oauth2buildAuthorizationUrl(
//		      wxMpService.getWxMpConfigStorage().getOauth2redirectUri(),
//		      WxConsts.OAUTH2_SCOPE_BASE, "cofay88.6655.la") + "\">测试oauth2</a>";
	  
	  
	  wxService.setWxMpConfigStorage(wxBaseService.getTokenByGroupId(1L));
	  
	  String href = "<a href=\"" + wxMpService.oauth2buildAuthorizationUrl(
		      "http://cofay88.6655.la/EBosService/api/oAuth2/index",
		      WxConsts.OAUTH2_SCOPE_BASE, "123") + "\">测试oauth2</a>";
	  
	  System.out.println(href); 
	  
		    return WxMpXmlOutMessage.TEXT().content(href)
		      .fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser())
		      .build();
	  
	  
	  
   // return WxMpXmlOutMessage.TEXT().content("测试").fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser()).build();
    
    
    
    
    
  }

}
